var storTable;
var btnAdvSearchflg = false;

// 初始化iCheck组件
turn_on_iCheck = function(domElement) {
    return $('input[type="checkbox"],input[type="radio"]', domElement).iCheck({
        checkboxClass : 'icheckbox_flat-red',
        radioClass : 'iradio_flat-red'
    });
};

jQuery(document)
        .ready(
                function() {
                    $("#storDetailForm").validate({
                        debug : true,
                        errorPlacement : function(error, element) {
                            error.insertAfter(element);
                        },
                        rules : {
                            txtStorName : {
                                required : true
                            },
                            txtStorCode : {
                                required : true
                            },
                            txtAddr : {
                                required : true
                            },
                            txtAreacode : {
                                required : true
                            },
                            storType : {
                                required : true
                            },
                            storModel : {
                                required : true
                            }
                        },
                        messages : {
                            txtStorName : "仓库名称不能为空，1-32位字符!",
                            txtStorCode : "仓库编码不能为空，1-50位字符!",
                            txtAddr : "地址不能为空！",
                            txtAreacode : "地区号不能为空！"
                        }
                    });

                    storTable = $('#storTable')
                            .DataTable(
                                    {
                                        "processing" : true,
                                        "serverSide" : true,
                                        "lengthMenu" : [ [ 10, 25, 50, -1 ], [ 10, 25, 50, "All" ] ],
                                        "dom" : '<"bottom"rtflp>',
                                        "searching" : false,
                                        "pagingType" : "full_numbers",
                                        "deferRender" : true,
                                        "ajax" : {
                                            "url" : "/stor/storList.action",
                                            "data" : function(d) {
                                                if ($("#advSearchPanel").is(":hidden")) {
                                                    d.quickSearch = encodeURI($('#quickSearch').val());
                                                } else {
                                                    // 高级查询条件
                                                    var gstorname = encodeURI($('#gstorname').val());
                                                    var gstorcode = encodeURI($('#gstorcode').val());
                                                    var advData = {
                                                        "storName" : gstorname,
                                                        "storCode" : gstorcode
                                                    };
                                                    d.formJson = JSON.stringify(advData);
                                                }
                                            }
                                        },
                                        "tableTools" : {
                                            "sRowSelect" : "bootstrap"
                                        },
                                        "columns" : [
                                                {
                                                    "data" : "chk"
                                                },
                                                {
                                                    "data" : "storName"
                                                },
                                                {
                                                    "data" : "storCode"
                                                },
                                                {
                                                    "data" : "storType",
                                                    "render" : function(data, type, row, meta) {
                                                        var returnValue = "未知";
                                                        var cainiaoType = row.cainiaoType || "gj";
                                                        if (data === "cainiao") {
                                                            var GNGJ = "国际";
                                                            if (cainiaoType === "gn") {
                                                                GNGJ = "国内";
                                                            }
                                                            returnValue = "菜鸟(" + GNGJ + ")";
                                                        } else if (data === "ext") {
                                                            returnValue = "第三方";
                                                        } else if (data === "local") {
                                                            returnValue = "本地库";
                                                        }
                                                        return returnValue;
                                                    }
                                                },
                                                {
                                                    "data" : "storModel",
                                                    "render" : function(data, type, row, meta) {
                                                        var returnValue = "未知";
                                                        if (data === "qm") {
                                                            returnValue = "奇门";
                                                        } else if (data === "normal") {
                                                            returnValue = "其它";
                                                        }
                                                        return returnValue;
                                                    }
                                                },
                                                {
                                                    "data" : "tel"
                                                },
                                                {
                                                    "data" : "mobile"
                                                },
                                                {
                                                    "data" : "operation",
                                                    "render" : function(data, type, row, meta) {
                                                        var storId = " storId='" + row.storId + "' ";
                                                        var storName = " storName='" + row.storName + "' ";
                                                        var qmCustomerid = " qmCustomerid='" + row.qmCustomerid + "' ";
                                                        var erpSecretkey = " erpSecretkey='" + row.erpSecretkey + "' ";
                                                        var wmsAppkey = " wmsAppkey='" + row.wmsAppkey + "' ";
                                                        var qmOwnercode = " qmOwnercode='" + row.qmOwnercode + "' ";
                                                        var cainiaoTypeCode = row.cainiaoType || "gj";
                                                        var cainiaoType = " cainiaoType='" + cainiaoTypeCode + "' ";
                                                        var returnValue = "";
                                                        if (row.storModel === "qm"&&row.storType === "ext") {
                                                            returnValue = "<button class='btn btn-info btn-xs' type='button' onclick='showStorParamSetting(this)' "
                                                                    + storId
                                                                    + qmCustomerid
                                                                    + erpSecretkey
                                                                    + wmsAppkey
                                                                    + qmOwnercode
                                                                    + " >"
                                                                    + "<i class='fa fa-cogs'></i>&nbsp;" + "参数</button>&nbsp;";
                                                        }

                                                        if (row.storType === "cainiao") {
                                                            var cainiaoTypeName = "国内";

                                                            if (cainiaoTypeCode && "gn" == cainiaoTypeCode) {
                                                                cainiaoTypeName = "国际";
                                                            }
                                                            
                                                            returnValue += "<button class='btn btn-info btn-xs' type='button' onclick='switchGNGJ(this)' "
                                                                    + storId
                                                                    + cainiaoType
                                                                    + storName
                                                                    + " >"
                                                                    + "<i class='fa fa-cogs'></i>&nbsp;" + "设为"+cainiaoTypeName+"</button>";

                                                        }
                                                        return returnValue;
                                                    }
                                                } ],
                                        "columnDefs" : [ {
                                            "orderable" : false,
                                            "targets" : [ 0 ]
                                        }, {
                                            "orderable" : false,
                                            "targets" : [ 5 ]
                                        }, {
                                            "orderable" : false,
                                            "targets" : [ 6 ]
                                        } ],
                                        "order" : [ [ 1, "desc" ], [ 2, "desc" ], [ 5, "desc" ] ]
                                    }).on('draw.dt', function() {
                                turn_on_iCheck($("#storTable"));
                                $("#chkAll").on("ifChanged", function() {
                                    if ($("#chkAll").is(":checked")) {
                                        $("#storTable").find(".icheck").iCheck("check");
                                    } else {
                                        $("#storTable").find(".icheck").iCheck("uncheck");
                                    }
                                });
                            });
                    // 构建省下拉列表
                    $.ajax({
                        type : "GET",
                        url : "/area/getProvList.action",
                        contentType : "application/json;charset=utf-8",
                        dataType : "json",
                        async : true,// 同步
                        success : function(data) {
                            if (data.result == "success") {
                                $("#provName option").remove();
                                $("#provName").append("<option value=''>请选择</option>");
                                $.each(data.data, function(n, value) {
                                    $('#provName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                                });
                            } else {
                                window.top.window.showModalAlert(data.msg);
                            }
                        },
                        error : function(XMLHttpRequest, textStatus) {
                            if (XMLHttpRequest.status == 500) {
                                var result = eval("(" + XMLHttpRequest.responseText + ")");
                                window.top.window.showModalAlert(result.errorObject.errorText);
                            }
                        }
                    });
                });

function switchGNGJ(element) {
    var storId = $(element).attr("storId");
    var storName = $(element).attr("storName");
    var cainiaoType = $(element).attr("cainiaoType");
    var cainiaoTypeName = "国内";

    if (cainiaoType && "gn" == cainiaoType) {
        cainiaoTypeName = "国际";
    }

    if (storId && cainiaoType) {
        window.top.window.showModalConfirm("是否确定将 " + storName + " 修改为 菜鸟("+cainiaoTypeName+")", function() {
        	var loading = window.top.window.getIndexBusyOverlay();
            // 构建省下拉列表
            $.ajax({
                type : "GET",
                url : "/stor/updateStorSwitchGJGN.action",
                contentType : "application/json;charset=utf-8",
                dataType : "json",
                data : {
                    "storId" : storId,
                    "cainiaoType" : cainiaoType
                },
//                async : false,// 同步
                beforeSend:function(){
                    if(loading) {
                    	loading.settext("正在处理中，请稍后...");
                    }
                },
                success : function(data) {
                	loading.remove();
                    if (data.result == "success") {
                        window.top.window.showScoMessage('ok', "操作成功");
                        storTable.draw();
                    } else {
                        window.top.window.showModalAlert(data.msg);
                    }
                },
                error : function(XMLHttpRequest, textStatus) {
                	loading.remove();
                    if (XMLHttpRequest.status == 500) {
                        var result = eval("(" + XMLHttpRequest.responseText + ")");
                        window.top.window.showModalAlert(result.errorObject.errorText);
                    }
                }
            });
        })
    } else {
        window.top.window.showModalAlert("更新失败，请联系系统管理员");
    }
}

$("#storType").on("change", function() {
    // 当选择本地仓时，仓库模式为其它
    if (window.top.window.$("#storType").val() == "local") {
        window.top.window.$("#storModel").attr("disabled", true).val("normal");
    } else {
        window.top.window.$("#storModel").removeAttr("disabled");
    }
    // 当选择三方仓时，放开
});

// 省变化的时候，市，区的值要变化
$('#provName').on('change', function() {
    if (window.top.window.$("#provName").val() == "") {
        window.top.window.$("#cityName").val("");
        window.top.window.$("#distName").val("");
    }

    // 构建市下拉列表
    $.ajax({
        type : "GET",
        url : "/area/getCityList.action?provId=" + window.top.window.$("#provName").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false, // 同步
        success : function(data) {
            if (data.result == "success") {
                window.top.window.$("#cityName option").remove();
                window.top.window.$("#cityName").append("<option value=''>请选择</option>");
                window.top.window.$("#distName option").remove();
                window.top.window.$("#distName").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    window.top.window.$('#cityName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
});

// 市变化的时候，区的值要变化
$('#cityName').on('change', function() {
    if (window.top.window.$("#cityName").val() == "") {
        window.top.window.$("#distName").val("");
    }

    // 构建区下拉列表
    $.ajax({
        type : "GET",
        url : "/area/getDistList.action?cityId=" + window.top.window.$("#cityName").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false, // 同步
        success : function(data) {
            if (data.result == "success") {
                window.top.window.$("#distName option").remove();
                window.top.window.$("#distName").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    window.top.window.$('#distName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
});

// 省变化的时候，市，区的值要变化
function setCitySelect() {
    // 构建市下拉列表
    $.ajax({
        type : "GET",
        url : "/area/getCityList.action?provId=" + $("#provName").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false, // 同步
        success : function(data) {
            if (data.result == "success") {
                $("#cityName option").remove();
                $("#cityName").append("<option value=''>请选择</option>");
                $("#distName option").remove();
                $("#distName").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#cityName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

// 市变化的时候，区的值要变化
function setDistSelect() {
    // 构建区下拉列表
    $.ajax({
        type : "GET",
        url : "/area/getDistList.action?cityId=" + $("#cityName").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false, // 同步
        success : function(data) {
            if (data.result == "success") {
                $("#distName option").remove();
                $("#distName").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#distName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

// 重置按钮
$("#advSearchReset").click(function() {
    $('#gstorname').val('');
    $('#gstorcode').val('');
});

// 低级查询按钮
$("#btnQuickSearch").click(function() {
    storTable.draw();
});

// 高级查询按钮
$("#advSearchSubmit").click(function() {
    setHidValue("frmAdvSearch");
    storTable.draw();
    $("#advSearchPanel").hide();
    $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
    $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
});

// 高级查询隐藏
$("#advSearchPanel").hide();
$("#btnAdvSearch").click(function() {
    btnAdvSearchflg = true;
    if ($("#advSearchPanel").is(":hidden")) {
        $("#advSearchPanel").show();
        $("#btnQuickSearch").hide();
        $(this).children("i:eq(0)").removeClass("fa-angle-double-down");
        $(this).children("i:eq(0)").addClass("fa-angle-double-up");
    } else {
        $("#advSearchPanel").hide();
        $("#btnQuickSearch").show();
        $(this).children("i:eq(0)").removeClass("fa-angle-double-up");
        $(this).children("i:eq(0)").addClass("fa-angle-double-down");
    }
});

$("#advSearchPanel").click(function() {
    btnAdvSearchflg = true;
})

$("body").click(function(e) {
    if (btnAdvSearchflg == true) {
        btnAdvSearchflg = false;
    } else {
        $("#advSearchPanel").hide();
        $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
        $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
    }
});

// 快速查询回车
$('#quickSearch').keydown(function(e) {
    if (e.keyCode == 13 && $('#btnQuickSearch').is(":visible")) {
        $('#btnQuickSearch').click();
    }
});

// 选择行
$('#storTable tbody').on('click', 'td', function() {
    var len = $(this).children().length
    if (len == 0) {// 选择行
        $("#storTable tbody input[type='checkbox']").prop("checked", false)
        var first = $(this).parent().children()[0];
        var ck = $(first).children()[0];
        $(ck).prop("checked", true)
    } else {// 选择checkbox

    }
})

// 全选
$(".checkall").click(function() {
    if ($(this).attr("checked")) {
        $("input[name='chkItem']").attr("checked", $(this).attr("checked"));
    } else {
        $("input[name='chkItem']").removeAttr("checked");
    }
});

// 删除
var storIdssum1 = "";
function deleteStor() {
    storIdssum1 = "";
    $("input[type='checkbox']:checked").each(function(k, v) {
        if (storIdssum1 == "") {
            storIdssum1 = this.getAttribute('storid');
        } else if (storIdssum1 != "") {
            storIdssum1 += "," + this.getAttribute('storid');
        }
    });
    if (storIdssum1 == null || storIdssum1 == undefined || storIdssum1 == "" || storIdssum1 == ",") {
        window.top.window.showModalAlert("请选择一个目标！");
        return;
    }
    window.top.window.showModalConfirm("确定要删除该仓库吗？", delStor);
}

function delStor() {
    var sURL = "/stor/deleteStor.action";
    $.ajax({
        url : sURL,
        type : "post",
        dataType : "json",
        async : false,
        data : {
            storIds : storIdssum1
        },
        success : function(data) {
            if (data.result == "success") {
                window.top.window.showScoMessage('ok', '删除成功');
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showModalAlert(result.errorObject.errorText);
            }
        }
    });
    storTable.draw();
}

// 父窗体归还本页的编辑对话框
$('#creatStor').on('hide.bs.modal', function() {
    // 父窗体归还本页的编辑对话框
    window.top.window.returnCustomModalDialog();
    ClearInput();
    $("#txtStorName").val("");
    $("#txtStorCode").val("");
    $("#storId").val("");
    $("#storName").val("");
    $("#txtTel").val("");
    $("#txtMobile").val("");
    $("#txtAddr").val("");
    $("#txtPostcode").val("");
    $("#txtAreacode").val("");
    $("#txtRemark").val("");
});

// 父窗体归还本页的编辑对话框
$('#storParamSetting').on('hide.bs.modal', function() {
    // 父窗体归还本页的编辑对话框
    window.top.window.returnCustomModalDialog();
    $("#txtMobile").val("");
    $("#txtAddr").val("");
    $("#txtPostcode").val("");
    $("#txtAreacode").val("");
});

// 新建仓库
function addStor() {
    $("#creatStor").find("#createTitle").html("新建仓库");
    $("#txtStorName").attr("disabled", false);

    $("#storType").val("");
    $("#storModel").val("");

    // 初始化省市区3级联动
    $("#provName").val("");
    $("#cityName").val("");
    $("#cityName option").remove();
    $("#cityName").append("<option value=''>请选择</option>");
    $("#distName").val("");
    $("#distName option").remove();
    $("#distName").append("<option value=''>请选择</option>");

    var editDialog = window.top.window.borrowCustomModalDialog($("#creatStor"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}

// 保存按钮
$('#storSave').click(function() {
    insertStor();
    storTable.draw();
});

// 新建/修改
function insertStor() {
    // 父窗体归还本页的编辑对话框
    window.top.window.returnCustomModalDialog();
    var txtStorName = $("#txtStorName").val();
    var txtStorCode = $("#txtStorCode").val();
    var updateStorName = $("#storName").val();
    var updateStorCode = $("#storCode").val();
    var txtTel = $("#txtTel").val();
    var txtMobile = $("#txtMobile").val();
    var txtAddr = $("#txtAddr").val();
    var txtPostcode = $("#txtPostcode").val();
    var txtAreacode = $("#txtAreacode").val();
    var txtRemark = $("#txtRemark").val();

    var storType = $("#storType").val();
    var storModel = $("#storModel").val();

    $.validator.addMethod("telValidate", function(value, element) {
        var RegTel = /^0\d{2,3}-?\d{7,8}$/;
        return (RegTel.test(value) || value == "-1");
    }, "电话号码不合法！");

    $.validator.addMethod("integerValidate", function(value, element) {
        var RegCellPhone = /^1\d{10}$/;
        return (RegCellPhone.test(value) || value == "-1");
    }, "手机号码不合法！");

    $.validator.addMethod("postcodeValidate", function(value, element) {
        var RegPostcode = /[1-9]\d{5}(?!\d)/;
        return (RegPostcode.test(value) || value == "-1");
    }, "邮编号码不合法！");

    if (!$("#storDetailForm").valid()) {
        // 父窗体借用本页的编辑对话框
        window.top.window.borrowCustomModalDialog($("#creatStor"));
        return false;
    }
    var loading = window.top.window.getIndexBusyOverlay();
    if ($("#storId").val() != null && $("#storId").val() != '') {
        var Sid = $("#storId").val();
        var data = {
            "storName" : txtStorName,
            "storCode" : txtStorCode,
            "storId" : Sid,
            "updateStorCode" : updateStorCode,
            "updateStorName" : updateStorName,
            "tel" : txtTel,
            "mobile" : txtMobile,
            "addr" : txtAddr,
            "postcode" : txtPostcode,
            "areacode" : txtAreacode,
            "provName" : $("#provName").find("option:selected").text(),
            "cityName" : $("#cityName").find("option:selected").text(),
            "distName" : $("#distName").find("option:selected").text(),

            "storType" : storType,
            "storModel" : storModel,

            "remark" : txtRemark
        };
        $.ajax({
            type : "POST",
            url : "/stor/updateStor.action",
            data : JSON.stringify(data),
            contentType : "application/json;charset=utf-8",
            dataType : "json",
//            async : false, // 同步
            beforeSend:function(){
                if(loading) {
                	loading.settext("正在处理中，请稍后...");
                }
            },
            success : function(data) {
            	loading.remove();
                if (data.result == "success") {
                    $('#creatStor').modal('hide');
                    window.top.window.showScoMessage('ok', '修改成功');
                } else {
                    window.top.window.showModalAlert(data.msg);
                    var editDialog = window.top.window.borrowCustomModalDialog($("#creatStor"));
                    editDialog.modal({
                        show : true,
                        backdrop : 'static'
                    });
                }
                storTable.draw();
            },
            error : function(XMLHttpRequest, textStatus) {
            	loading.remove();
                if (XMLHttpRequest.status == 500) {
                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                    window.top.window.showModalAlert(result.errorObject.errorText);
                }
            }
            
        });

    } else {
        var data = {
            "storName" : txtStorName,
            "storCode" : txtStorCode,
            "tel" : txtTel,
            "mobile" : txtMobile,
            "addr" : txtAddr,
            "postcode" : txtPostcode,
            "areacode" : txtAreacode,
            "provName" : $("#provName").find("option:selected").text(),
            "cityName" : $("#cityName").find("option:selected").text(),
            "distName" : $("#distName").find("option:selected").text(),

            "storType" : storType,
            "storModel" : storModel,

            "remark" : txtRemark
        };
        $.ajax({
            type : "POST",
            url : "/stor/addStor.action",
            data : JSON.stringify(data),
            contentType : "application/json;charset=utf-8",
            dataType : "json",
//            async : false, // 同步
            beforeSend:function(){
                if(loading) {
                	loading.settext("正在处理中，请稍后...");
                }
            },
            success : function(data) {
            	loading.remove();
                if (data.result == "success") {
                    $('#creatStor').modal('hide');
                    window.top.window.showScoMessage('ok', '添加成功');
                } else {
                    window.top.window.showModalAlert(data.msg);
                    var editDialog = window.top.window.borrowCustomModalDialog($("#creatStor"));
                    editDialog.modal({
                        show : true,
                        backdrop : 'static'
                    });
                }
                storTable.draw();
            },
            error : function(XMLHttpRequest, textStatus) {
            	loading.remove();
                if (XMLHttpRequest.status == 500) {
                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                    window.top.window.showModalAlert(result.errorObject.errorText);
                }
            }
        });
    }
    storTable.draw();
    $("#txtStorName").val("");
    $("#txtStorCode").val("");
    $("#storId").val("");
    $("#storName").val("");
    $("#txtTel").val("");
    $("#txtMobile").val("");
    $("#txtAddr").val("");
    $("#txtPostcode").val("");
    $("#txtAreacode").val("");
    $("#txtRemark").val("");

    $("#storType").val("");
    $("#storModel").val("");
}

// 修改用户
function updateStor() {
    $("#creatStor").find("#createTitle").html("修改仓库");
    var idString = "";
    $("input[type='checkbox']:checked").each(function(k, v) {
        if (idString == "") {
            if (this.getAttribute('storid') != null)
                idString = this.getAttribute('storid');
        } else if (idString != "") {
            if (this.getAttribute('storid') != null)
                idString += "," + this.getAttribute('storid');
        }
    });

    if (idString == null || idString == undefined || idString == "" || idString == ",") {
        window.top.window.showModalAlert("请选择仓库");
        return;
    } else if (idString.split(",").length > 1) {
        window.top.window.showModalAlert("只能选择一个仓库");
        return;
    } else {
        // 获取选中行的数据
        // debugger;
        var rowData = storTable.row($("input[type='checkbox']:checked").eq(0).closest("tr")).data();
        // 如果选中行数据的仓库类型是菜鸟，不能编辑
        if (rowData.storType === "cainiao") {
            window.top.window.showModalAlert("菜鸟仓库不能编辑");
            return;
        }
    }
    var sURL = "/stor/getStorDetail.action";
    jQuery.ajax({
        url : sURL,
        type : "post",
        dataType : "json",
        data : {
            storId : idString
        },
        async:false,
        success : function(data) {
            if (data.errorMessage == undefined) {
                $("#storId").val(data.storDetail.storId);
                $("#txtStorName").val(data.storDetail.storName);
                $("#txtStorName").attr("disabled", true)
                $("#txtStorCode").val(data.storDetail.storCode);
                $("#storName").val(data.storDetail.storName);
                $("#storCode").val(data.storDetail.storCode);
                $("#txtTel").val(data.storDetail.tel);
                $("#txtMobile").val(data.storDetail.mobile);
                $("#txtAddr").val(data.storDetail.addr);
                $("#txtPostcode").val(data.storDetail.postcode);
                $("#txtAreacode").val(data.storDetail.areacode);
                $("#txtRemark").val(data.storDetail.remark);

                //$("#storType").val(data.storDetail.storType).attr("disabled", true);
                //$("#storModel").val(data.storDetail.storModel).attr("disabled", true);
                // if(data.storDetail.storType=="local"){
                // $("#storModel").attr("disabled",true).val("normal");
                // }else{
                // $("#storModel").removeAttr("disabled").val(data.storDetail.storModel);
                // }

                // 填省市区
                $("#provName").find("option:contains('" + data.storDetail.provName + "')").attr("selected", true);
                setCitySelect();
                $("#cityName").find("option:contains('" + data.storDetail.cityName + "')").attr("selected", true);
                setDistSelect();
                $("#distName").find("option:contains('" + data.storDetail.distName + "')").attr("selected", true);

                $("#createTitle").html("修改仓库");
                var editDialog = window.top.window.borrowCustomModalDialog($("#creatStor"));
                editDialog.modal({
                    show : true,
                    backdrop : 'static'
                });
            } else {
                if (data.errorMessage == "session timeout") {
                    window.location.href = "/login.jsp";
                } else {
                    window.top.window.showModalAlert(data.errorMessage);

                }
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            window.top.window.showModalAlert("操作失败，可能是网络原因");
        }
    });
}

function ClearInput() {
    // 清空输入域
    var validator = $("#storDetailForm").validate({
        submitHandler : function(form) {
            form.submit();
        }
    });
    $('#storDetailForm .state-error').removeClass('state-error');
    $('#storDetailForm .state-success').removeClass('state-success');
}

// 保存按钮
$('#storParamSave').click(function() {
    saveStorParamSetting();
});

/**
 * 显示仓库参数设置对话框
 */
function showStorParamSetting(element) {
    var storId = $(element).attr("storId")
    var qmCustomerid = $(element).attr("qmCustomerid")
    var erpSecretkey = $(element).attr("erpSecretkey")
    var wmsAppkey = $(element).attr("wmsAppkey")
    var qmOwnercode = $(element).attr("qmOwnercode")

    $("#hideStorId").val(storId);
    $("#qmCustomerid").val(qmCustomerid);
    $("#erpSecretkey").val(erpSecretkey);
    $("#wmsAppkey").val(wmsAppkey);
    $("#qmOwnercode").val(qmOwnercode);

    var paramSettingDialog = window.top.window.borrowCustomModalDialog($("#storParamSetting"));
    paramSettingDialog.modal({
        show : true,
        backdrop : 'static'
    });
}

/**
 * 保存仓库参数设置
 * 
 * @returns
 */
function saveStorParamSetting() {
	var loading = window.top.window.getIndexBusyOverlay();
    var data = {
        "storId" : $("#hideStorId", window.top.document).val(),
        "qmCustomerid" : $("#qmCustomerid", window.top.document).val(),
        "erpSecretkey" : $("#erpSecretkey", window.top.document).val(),
        "wmsAppkey" : $("#wmsAppkey", window.top.document).val(),
        "qmOwnercode" : $("#qmOwnercode", window.top.document).val()
    };
    $.ajax({
        type : "POST",
        url : "/stor/updateStor.action",
        data : JSON.stringify(data),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
//        async : false, // 同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                $('#storParamSetting', window.top.document).modal('hide');
                storTable.draw();
                window.top.window.showScoMessage('ok', '保存参数成功');
            } else {
                window.top.window.showModalAlert(data.msg);
                var paramSettingDialog = window.top.window.borrowCustomModalDialog($("#storParamSetting"));
                paramSettingDialog.modal({
                    show : true,
                    backdrop : 'static'
                });
            }
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showModalAlert(result.errorObject.errorText);
            }
        }
    });
}